package com.itheima.homework;

/**
 * @Author 王加鑫
 * @Date 2021/4/26 20:09
 * @Version 1.0
 * 7、【编号：707】 请定义一个描述矩形（MyRectangle）的类，包含宽和高两个属性，提供获取矩形周长（perimeter）和面积（area）的方法。
 * 并编写测试类进行测试。
 */
public class Day07HomeWork07 {
    public static void main(String[] args) {
        MyRectangle rectangle = new MyRectangle(10,20);
        double perimeter = rectangle.getPerimeter();
        double area = rectangle.getArea();
        System.out.println("周长为:" + perimeter);
        System.out.println("面积为:" + area);
    }

}


class MyRectangle{
    //长
    private double length;
    //宽
    private double height;

    public MyRectangle() {
    }

    public MyRectangle(double length, double height) {
        this.length = length;
        this.height = height;
    }

    public double getLength() {
        return length;
    }

    public void setLength(double length) {
        this.length = length;
    }

    public double getHeight() {
        return height;
    }

    public void setHeight(double height) {
        this.height = height;
    }

    /*
    获取矩形周长
     */
    public double getPerimeter(){
        return (getLength() + getHeight()) * 2;
    }

    /*
    获取面积
     */
    public double getArea(){
        return getLength() * getHeight();
    }
}
